//
//  STServiceCell.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/9/30.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STServiceCell.h"

@implementation STServiceCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self = [[[NSBundle mainBundle] loadNibNamed:@"STServiceCell" owner:nil options:nil] lastObject];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self loadBtnView];
    return self;
}


-(void)loadBtnView{
    self.changeBtn.layer.borderColor = [UIColor redColor].CGColor;
    self.changeBtn.layer.borderWidth = 1;
    self.dowmBtn.layer.borderColor = [UIColor blackColor].CGColor;
    self.dowmBtn.layer.borderWidth = 1;
    
}


-(void)setServiceCellType:(int)type{
    if (type == 0 ) {
        [self.changeBtn setTitle:@"修改" forState:UIControlStateNormal];
        [self.dowmBtn setTitle:@"下架" forState:UIControlStateNormal];
    }else{
        [self.changeBtn setTitle:@"上架" forState:UIControlStateNormal];
        [self.dowmBtn setTitle:@"删除" forState:UIControlStateNormal];
    }
}

-(void)setServiceCellModel:(id)model{
    STHairServiceInfoModel * serviceModel = model;
    self.nameLab.text = serviceModel.serviceName;
    
    NSString * priceStr = [self isPureFloat:serviceModel.price];
    NSString * fromPriceStr = [self isPureFloat:serviceModel.fromPrice];
    NSString * endPriceStr = [self isPureFloat:serviceModel.toPrice];
    
    if(serviceModel.priceType ==1){
        self.priceLab.text = [NSString stringWithFormat:@"¥%@",priceStr];
    }else{
        self.priceLab.text = [NSString stringWithFormat:@"¥%@-¥%@",fromPriceStr,endPriceStr];;
    }
    
    self.acceptTimerLab.text =  [NSString stringWithFormat:@"%@-%@",serviceModel.begintime,serviceModel.endtime];;;
    self.termLab.text =[NSString stringWithFormat:@"%d",serviceModel.deadline];
    if(serviceModel.storeLimit ==0 ){
        self.doorLab.text =@"不限";
    }else{
        self.doorLab.text =@"门店限制";
    }
    self.sellNumLab.text =[NSString stringWithFormat:@"%d",serviceModel.sell];
 
}

//判断是否为浮点形：

- (NSString *)isPureFloat:(float)price{
    NSString * str = [NSString stringWithFormat:@"%0.2f",price];
    NSArray * arr = [str componentsSeparatedByString:@"."];
    NSString * last = arr.lastObject;
    if([last isEqualToString:@"00"]){
        return arr.firstObject;
    }else{
        return str;
    }
    
    
}

@end
